#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

#define FIFO_NAME "05_TEST.fifo"

int main(int argc, char const *argv[])
{
    int iRet;
    iRet =  mkfifo( FIFO_NAME, 0667 );
    if ( iRet == -1 && errno != EEXIST )
    {
        perror( "fail mkfifo in read.c");
        return -1;
    }

    int fdRead;
    fdRead = open( FIFO_NAME, O_RDONLY );
    if ( fdRead == -1 )
    {
        perror( "fail open in read.c" );
        return -1;
    }

    char strBuffRead[100] = {0};
    iRet = read( fdRead, strBuffRead, sizeof(strBuffRead) );
    if ( iRet == -1 )
    {
        perror( "fail read in read.c");
        return -1;
    }
    printf( "Read from <%s>: %s\n", FIFO_NAME, strBuffRead );

    close( fdRead );
    remove( FIFO_NAME );

    
    return 0;
}


/*
从指定的 FIFO 文件读取一个字符串

流程
    mkfifo
    open
    read
    close
    remove

*/